package org.example.controller;

import org.example.webmagic.DataPipe;
import org.example.webmagic.SXSProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

//@SuppressWarnings("ALL")
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@RestController
public class SpiderController {

    @Autowired
    private SXSProcessor sxsProcessor;

    @Autowired
    private DataPipe dataPipe;


    /**
     * 通过URL触发爬虫执行
     */
    @GetMapping("/spider")
    public String spider() {

        Spider.create((PageProcessor) sxsProcessor)
//                .addUrl("https://xiaoyuan.shixiseng.com/wangshen?p=1&j=opj_aepdep2mgrcj")
                .addUrl("https://xiaoyuan.shixiseng.com/wangshen?pd=4&j=opj_aepdep2mgrcj")      //测试爬完的操作，有两条数据
                .addPipeline(dataPipe)
                .thread(1)
                .run();
        return "success";
    }
}
